﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class BOMEntityProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<BOMEntity> entryList = new List<BOMEntity>();

            BOMEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new BOMEntity();
                    entry.Company = item[BOMEntity.COMPANY].ToString();
                    entry.CurrPart = item[BOMEntity.CURRPART].ToString();
                    entry.LastPart = item[BOMEntity.LASTPART].ToString();
                    entry.Leave = item[BOMEntity.LEAVE].ToString();
                    entry.MtlSeq = item[BOMEntity.MTLSEQ].ToString();
                    entry.Netweight = decimal.Parse(item[BOMEntity.NETWEIGHT].ToString());
                    entry.OperCode = item[BOMEntity.OPERCODE].ToString();
                    entry.OperCodeDesc = item[BOMEntity.OPERCODEDESC].ToString();
                    entry.PartDescription = item[BOMEntity.PARTDESCRIPTION].ToString();
                    entry.QtyPer = decimal.Parse(item[BOMEntity.QTYPER].ToString());
                    entry.Rev = item[BOMEntity.REV].ToString();
                    entry.Type = item[BOMEntity.TYPE].ToString();
                    entry.UOM = item[BOMEntity.U_O_M].ToString();
                    entry.PartIum = item[BOMEntity.PARTIUM].ToString();
                    entry.PartDesc = item[BOMEntity.PARTDESC].ToString();
                    entry.PartNewweight = decimal.Parse(item[BOMEntity.PARTNEWWEIGHT].ToString());
                    entry.MouldJob = item[BOMEntity.MOULDJOB].ToString();
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
